package cn.istartfinancial.entity;

import cn.istartfinancial.annotation.group.AddGroup;
import cn.istartfinancial.annotation.group.UpdateGroup;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author: Nzp
 * @date: 2018/8/22
 * @description: 系统菜单实体类
 */
@Data
@EqualsAndHashCode
@Table(name = "sys_menu")
public class SysMenu
{
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(generator = "JDBC")
    private String id;
    @NotEmpty(message = "菜单名称不能为空", groups = {AddGroup.class, UpdateGroup.class})
    private String name;
    @Column(name = "p_id")
    private String pId;
    private String url;
    /**
     * 排序字段
     */
    @Length(min = 1, max = 4, message = "序号长度不对")
    @Column(name = "order_num")
    private Integer orderNum;
    /**
     * 图标
     */
    private String icon;
    @Column(name = "create_by")
    private String createBy;
    @Column(name = "create_date")
    private Date createDate;
    @Column(name = "update_by")
    private String updateBy;
    @Column(name = "update_date")
    private Date updateDate;
    /**
     * 权限
     */
    private String permission;
    /**
     * 1栏目2菜单
     */
    @Column(name = "menu_type")
    private Byte menuType;
    private int num;
    private List<SysRole> roleList;
    private List<SysMenu> children = new ArrayList<SysMenu>();

    public void addChild(SysMenu sysMenu)
    {
        children.add(sysMenu);
    }
}